<?php 

//用户控制器
class UserController extends Controller
{
    private $model = null;//存放模型对象

    public function __construct()
    {
        //将父类的同名方法再一次调用执行
        parent::__construct();
        $this->model = new Model('user');
    }

    public function index ()
    {
        $data = $this->model->order('id desc')->select();
        $this->assign('title', '用户列表');
        $this->assign('list', $data);
        $this->display('User/index.html');
        
    }

    // 执行删除
    public function del()
    {
        if ($this->model->del($_GET['id'])) {
            $this->redirect('恭喜您,删除成功!', './index.php?c=user');
        } else {
            $this->redirect('您,删除失败!', './index.php?c=user');
        }
    }

    //加载表单
    public function add()
    {
        $this->assign('title', '填个用户拉~');
        $this->display('User/add.html');
    }

    //执行添加
    public function insert()
    {
        if ($this->model->add() > 0) {
            $this->redirect('恭喜您,添加成功!', './index.php?c=user');
        } else {
            $this->redirect('添加失败鸟~');
        }
    }


    
}





